package com.yidu.t299.dao.chr;

import com.yidu.t299.domain.chr.Grade;
import com.yidu.t299.domain.chr.Lesson;
import com.yidu.t299.domain.chr.StudentManage;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface GradessMapper {

    @Select("SELECT * FROM grade g\n" +
            "            JOIN student_manage sm\n" +
            "            ON sm.student_id = g.student_id\n" +
            "            JOIN school s\n" +
            "            ON s.school_id = sm.school_id\n" +
            "            JOIN class c\n" +
            "            ON c.class_id = sm.class_id\n" +
            "            JOIN lesson l\n" +
            "            ON l.lesson_id = g.lesson_id\n" +
            "            join record r" +
            "            on r.record_id=sm.record_id" +
            "            where 1=1 ${condition} " +
            "            ORDER BY lesson_name,lesson_grade DESC" +
            "            limit #{page},#{rows}")
    @Results({
            @Result(column = "grade_id", property = "gradeId", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "lesson_grade", property = "lessonGrade", jdbcType = JdbcType.INTEGER),
            @Result(column = "student_id", property = "studentId", jdbcType = JdbcType.INTEGER),
            @Result(column = "lesson_id", property = "lessonId", jdbcType = JdbcType.INTEGER),
            @Result(column = "student_id", property = "studentManage", javaType = StudentManage.class
                    , one = @One(select = "com.yidu.t299.dao.chr.StudentManageMapper.selectByPrimaryKey")),
            @Result(column = "lesson_id", property = "lesson", javaType = Lesson.class
                    , one = @One(select = "com.yidu.t299.dao.chr.LessonMapper.selectByPrimaryKey"))
    })
    List<Grade> selectByPage(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);
}
